$(function() {
    let orderId = getQueryString("orderId");
    getOrderProduct(orderId);
    getOrderAddress(orderId);

})
//展示商品详细信息
function getOrderProduct(orderId) {
    let url = "/item/selectItemByOrderId";

    let params={
        orderId:orderId
    }
    httpGet(url,params,function (data) {
        renderingOrderProduct(data);
    })
}
function renderingOrderProduct(itemList) {
    let templateItemListHtml = $("#template_item").html();
    let ItemListHtml = "";
    let tempItemListHtml;
    let count =1;
    //遍历商品列表
    $.each(itemList,function (index,item) {
        //后台数据填充到模板
        tempItemListHtml=templateItemListHtml.replace(/{count}/g,count)
            .replace(/{productName}/g,item.product.name)
            .replace(/{productState}/g,item.product.star)
            .replace(/{productTime}/g,item.product.creatTime)
            .replace(/{productPrice}/g,item.product.price)
            .replace(/{itemCount}/g,item.itemTotalPrice)
            .replace(/{itemNum}/g,item.itemNum)
            .replace(/{picture}/g,item.product.picture);

        ItemListHtml+=tempItemListHtml;
        count++;
    });
    $("#orderDetailHead").after(ItemListHtml);
}

//展示地址信息和订单信息
function getOrderAddress(orderId) {
    let url = "/order/selectOrderByOrderId";
    let params={
        orderId:orderId
    }
    httpGet(url,params,function (data) {
        renderingOrderAddress(data);
    })
}
function renderingOrderAddress(order) {
    $("#orderId").html(order.orderId);
    $("#orderTime").html(order.orderCreatedTime);
    $("#addressName").html(order.address.name);
    $("#addressPhone").html(order.address.phone);
    $("#addressDetail").html(order.address.detail);
    $("#orderCount").html(order.totalPrice);
    $("#orderIntegral").html(order.integral);
}



function getQueryString(name) {
    //获取地址栏url的参数
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) {
        return unescape(r[2]);
    }
    return null;
}